import 'package:domain/usecases/home_article_use_case.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:get_it/get_it.dart';

class SplashPage extends StatelessWidget {
  const SplashPage({super.key});

  @override
  Widget build(BuildContext context) {
    return GetBuilder<SplashController>(
      init: SplashController(
        homeArticleUseCase: GetIt.instance<HomeArticleUseCase>(),
      ),
      builder: (controller) => Scaffold(
        backgroundColor: Colors.white,
        body: SafeArea(
          child: Column(
            children: [
              ElevatedButton(
                onPressed: () {
                  // Get.toNamed(RouteNames.mainPage);
                },
                child: Text("to main page"),
              ).marginOnly(top: 30, bottom: 30),
              ElevatedButton(
                onPressed: () {
                  controller.foo();
                },
                child: Text("load"),
              ),
            ],
          ),
        ),
      ),
    );
  }
}

class SplashController extends GetxController {
  final HomeArticleUseCase _homeArticleUseCase;

  SplashController({required HomeArticleUseCase homeArticleUseCase})
    : _homeArticleUseCase = homeArticleUseCase;

  Future<void> foo() async {
    final list = await _homeArticleUseCase.fetchArticles();
    debugPrint(list.toString());
  }
}
